﻿using System;

namespace Bowling_Scorer
{
    public class ScoreBowling
    {

        public int CalculateScore(string rolls)
        {
            int score = 0;
            int roll = 0;

            string[] stringRollArray = rolls.Split(',');

            int[] intRollArray = new int[stringRollArray.Length];
            for (int i = 0; i < stringRollArray.Length; i++)
            {
                stringRollArray[i] = stringRollArray[i].Replace("X", "10");

                if (stringRollArray[i] == "/")
                {
                    stringRollArray[i] = stringRollArray[i].Replace("/", (10 - Convert.ToInt32(stringRollArray[i - 1])).ToString());
                }

                intRollArray[i] = Convert.ToInt32(stringRollArray[i]);
            }

            for (int i = 0; i < 10; i++)
            {


                if (intRollArray[roll] == 10)
                {
                    score += 10 + intRollArray[roll + 1] + intRollArray[roll + 2];
                    roll++;
                }
                else if (intRollArray[roll] + intRollArray[roll + 1] == 10)
                {
                    score += (10 + intRollArray[roll + 2]);
                    roll += 2;
                }

                else
                {
                    score += intRollArray[roll] + intRollArray[roll + 1];
                    roll += 2;
                }
            }

            return score;
        }

    }
}
